package com.springcloud.market.pay.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.function.Consumer;

@Service
public class OrderTimeoutHandler {

    private static final Logger logger = LoggerFactory.getLogger(OrderTimeoutHandler.class);

    /**
     * 函数式消费者：收到延迟超时消息后执行取消逻辑
     * 与 application.yml 里 binding: orderCancelConsumer-in-0 对应
     */
    @Bean
    public Consumer<String> orderCancelConsumer() {
        return orderId -> {
            logger.info("[消费者] 收到订单超时消息，订单ID：{}", orderId);
            // TODO: 这里调用真正的订单取消逻辑（更新状态、释放库存、退款等）
            System.out.println(orderId + " 订单取消了");
            logger.warn("执行订单取消逻辑，订单ID：{}", orderId);
        };
    }
}